<!-- ThanhLD1 this script to load more posts at button read more -->
<script>
$(function(){
    $more=$('#more');
    $text_default=$more.text();
    $(window).bind("load", function() {
    	$more.text($text_default);
    });
    $start=parseInt($more.attr('datastart'));
    $rows=10;
    $more.click(function(){
        if(!$(this).hasClass('clicked')){      
            $page=Math.ceil($start/$rows)+1;
            $more.text('Loading ....').attr({
                'href':'?p='+$page
            });
            pageurl = $more.attr('href');
	        window.history.pushState({path:pageurl},'',pageurl);
            $start+=$rows;

            //hungdv7 reload page
            location.reload();
        }

        return false;
    });
    
    //check are have more posts
    $.post(
            '/posts/process',
            {start:$start},
            function(data){
                if(!data){
                    $more.remove();
                }
            }
    );
});
</script>

<style>
html,body {
	height: 100%;
}

</style>

<body data-spy="scroll" data-target="#myScrollspy">

	<div class="row">
		<div class="col-md-3">
			<div id="container-fluid">
            <?php foreach ($posts as $post): ?>
            	<div class="row contentPost"
					id="<?php echo $this->Time->format ('F_Y', $post['Post']['created'], null, new DateTimeZone('Asia/Saigon') );?>">
					<div class="col-xs-6 col-md-3 contentPost-left">
						<div class="postCreated" align="center" style="margin-top: 20px">
							<div align="right">

							<?php	//split datetime variable to day, month, year variable - ThanhLD1
													list ( $y, $m, $dh ) = explode ( '-', $post ['Post'] ['created'] );
													list ( $d, $h ) = explode ( ' ', $dh );
													?>
							<h1>

									<small class="datetime-year"><?php echo $y;?></small><br /> <span
										class="datetime-date"><?php echo $d;?></span><span
										class="datetime-month">/<?php echo $m;?></span>
								</h1>

							</div>

							<hr />
							<img
								src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTJfM-cz_DDwZpaT9SNHNSHJpMhdTbPVbM62bFPEDGREECUmcZptg"
								class="img-circle img-avatarS"> <strong class="nickname-show"><a
								href="/admins/manageclick/<?php echo $post['Post']['Admin_id']?>"><?php echo $post ['Post'] ['Username']; ?></a></strong>
							<br />

							<div class="bd-top-small"></div>
							<small><?php echo $post['Post']['created'];?></small>

						</div>

					</div>
					<div class="col-xs-12 col-md-8 contentPost-right">
						<h1>
							<a href="/posts/view/<?php echo $post['Post']['id'];?>"><?php if(strlen($post['Post']['title']) > 28) echo substr($post['Post']['title'], 0,28)."...."; else echo $post['Post']['title']; ?></a>
						</h1>
						<div class="bd-top"></div>
						<br />
						<div class="row" style="text-align: center;">
							<img
								src="<?php
													//if have thumbnail show that thumbnail, if not show picture "image not avalible" - ThanhLD1
													if ($post ['Post'] ['thumbnail'])
														echo $post ['Post'] ['thumbnail'];
													else
														echo "http://www.weefmgrenada.com/images/na.jpg";
													?>"
								class="img-thumbnail img-thumbnailS"> <br /> <br />


						</div>
						<div class="row" style="margin-left: 2px">

				<?php echo $post['Post']['body'];?>
				</div>
						<br /> <a href="/posts/view/<?php echo $post['Post']['id'];?>">Continues
							reading ...</a>


						<div class="bd-bottom"></div>
						<br /> <br />

					</div>

				</div>
				<div class="row" style="height: 20px"></div>

            <?php endforeach;?>
		</div>

		</div>

		<!-- Sidebar -->
		<div class="col-md-offset-10" id="">
				<?php
				echo $this->element ( 'sidebar', array (
						"sideBarList" => $dateTimeList 
				) );
				?>				
						
	</div>

		<!-- End Sidebar -->

	</div>
	
	
	<div class="row">
	<div class="text-center">
		<div id="more" class="btn btn-custom col-md-8 btn-readmore"
			datastart="<?php echo $p*10;?>"><strong>Read more ...</strong></div>
			</div>
	</div>




</body>